layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格id
    };

    /**
     * 初始化年
     */
    var dd = new Date();
    var curtyear = dd.getFullYear();
    var curtMonth = dd.getMonth()+1;
    var dateHtml='';
    for(var i=2015;i<=curtyear;i++){
        if(i == curtyear) {
            dateHtml+='<option value="'+i+'" selected>'+i+'</option>';
        } else {
            dateHtml+='<option value="'+i+'">'+i+'</option>';
        }

    }
    $('#year').append(dateHtml);
    form.render();
    /**
     * 初始化月
     */
    var dateMonthHtml='';
    for(var i=1;i<=12;i++){
        /*if(i == curtMonth) {
            dateMonthHtml+='<option value="'+i+'" selected>'+i+'</option>';
        } else {
            dateMonthHtml+='<option value="'+i+'">'+i+'</option>';
        }*/

        dateMonthHtml+='<option value="'+i+'">'+i+'</option>';


    }
    $('#month').append(dateMonthHtml);
    form.render();



    /**
     * 初始化日
     */
    var dateDayHtml='';
    for(var i=1;i<=31;i++){
        dateDayHtml+='<option value="'+i+'">'+i+'</option>';
    }
    $('#day').append(dateDayHtml);
    form.render();




    Notice.getDate = function(){
        var dd = new Date();
        var y = dd.getFullYear();
        var m = dd.getMonth()+1;//获取当前月份的日期
        var d = dd.getDate();
        //判断 月
        /*if(m < 10){
            m =
        }else{
            m = m;
        }*/
        m=m < 10?("0" + m):m;
        d=d < 10?("0" + d):d;
        return y+"-"+m+"-"+d;
    }

    /**
     * 选中行效果
     */
    table.on('row(noticeTable)', function (obj) {
        $(obj.tr).siblings().css("background-color", "");
        obj.tr.css({"background-color": "#dadad9"});
    });


    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id'},
            {align: 'center', type: "numbers", title: '序号', style: 'font-size:11px;',width:50},
            {field: 'name', align: "left", sort: true, title: '店名', width: 320},
            {field: 'yjkyriqi', align: "left", sort: true, title: '预计开业时间'},
            {field: 'content', align: "left", sort: true, title: '开业时间'},
            {field: 'createUser', align: "left", sort: true, title: '开发人员'},
            {field: 'yyjl', align: "left", sort: true, title: '营运经理'},
            {field: 'dd', align: "left", sort: true, title: '督导'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['name'] = $("#name").val();
        queryData['ghs'] = $("#ghs").val();
        queryData['status'] = $("#status").val();
        queryData['kyFlag'] = $('#allStautusEnd').val();
        queryData['kyDate'] = '';
        queryData['year'] = $('#year').val();
        queryData['month'] = $('#month').val();
        queryData['day'] = $('#day').val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };



    // 渲染表格
    table.render({
        elem: '#' + Notice.tableId,
        url: '/btyBxd/listKY',
        page: true,
        even: true,
        cellMinWidth: 100,
        limit: 20,
        totalRow: true,	//开启合计行
        where:{kyDate:Notice.getDate()},
        cols: Notice.initColumn(),
    });

    Notice.search();
    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });

    $("#todayKY").click(function(){
        $('#allStautusEnd').val('Y');
        form.render();
        table.reload(Notice.tableId, {
            where: {kyDate:Notice.getDate()}, page: {curr: 1}
        });
    });


    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'delete') {
            Notice.onDeleteNotice(data);
        } else if (layEvent === 'editKj') {
            Notice.onEditKj(data);
        }
    });
});
